<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <meta name="format-detection" content="telephone=no" />
  <meta name="format-detection" content="email=no" />
  <title>首页</title>
  <link rel="stylesheet" href="../../css/api.css">
  <link rel="stylesheet" href="../../css/vant.css">
  <link rel="stylesheet" href="../../css/main.css">
  <style>
    html,
    body {
      background: #fff;
    }
  </style>
</head>

<body>
  <div class="app store-all" v-cloak>
    <div class="baby-list">
      <div class="baby-item" v-for="(item,index) in listProduct" :key="index" @click="goPage(item)">
        <img v-lazy="item.imageUrl?item.imageUrl:'https://zzzzkj.oss-cn-shanghai.aliyuncs.com/static/tiexie/app/image/image/default/item_img.png'" alt="">
        <div class="baby-item-info">
          <div class="title">{{item.title}}</div>
          <div class="money"><span v-if="item.price<10000 && item.price!==null">¥ </span>{{item.price | filterPrice}}</div>
        </div>
      </div>
    </div>
    <div class="collect-empty" v-if="listProduct&&listProduct.length===0">
      <img src="https://zzzzkj.oss-cn-shanghai.aliyuncs.com/static/tiexie/app/image/image/empty/empty.png" alt="">
      <div>暂无商品～</div>
    </div>
  </div>

  </div>
  <script src="../../script/api.js "></script>
  <script src="../../script/flexible.js "></script>
  <script src="../../script/fastclick.js "></script>
  <script src="../../script/vue.min.js "></script>
  <script src="../../script/iconfont.js "></script>
  <script src="../../script/vant.min.js"></script>
  <script src="../../script/restful.js"></script>
  <script src="../../script/businessCommon.js"></script>
  <script src="../../script/vue-lazyload.js"></script>
  <script src="../../script/common.js"></script>

  <script>
    apiready = function () {
      imgLazyLoad();
      var vm = new Vue({
        el: '.app',
        data() {
          return {
            listProduct: [],
            hasNext: true,
            // 列表查询参数
            queryParam: {
              types: [0, 1, 2], // types 类型：0设备售卖 1设备出租 2配件
              location: null,
              newed: null,
              orderBy: null,
              pageNum: 1,
              pageSize: 10,
              queryOwn: null,
              recommended: null,
              status: 1,
              checkStatus:1,
              userId: null,
            },
          }
        },
        filters: {
          filterPrice: filterPrice
        },
        mounted() {
          if(api.pageParam.queryOwn){
            this.queryParam.queryOwn = true
          }else{
            this.queryParam.userId = api.pageParam.storeInfo.userId
          }
          this.getListProducts()
        },
        methods: {
          goPage(item) {
            api.openWin({
              name: 'goods_detail_win',
              url: '../whole_sale/goods_detail_win.html',
              bounces: false,
              pageParam: {
                detailItem: item
              }
            });
          },
          getListProducts() {
            var vm = this;
            this.queryParam.userId = api.pageParam.storeInfo.userId
            index.product("getListProducts")(vm.queryParam, function (ret) {
              console.log("数据：" + JSON.stringify(ret));
              if (vm.queryParam.pageNum == 1) {
                vm.listProduct = ret.data.list
              } else {
                vm.listProduct = vm.listProduct.concat(ret.data.list)
              }
              vm.hasNext = ret.data.hasNext
            })
          }
        }
      })
      api.setRefreshHeaderInfo({
        bgColor: '#f7f7f7',
        textDown: '下拉更新有惊喜',
        textUp: '松开可以刷新'
      }, function (ret, err) {
        vm.queryParam.pageNum = 1
        vm.listProduct = []
        vm.getListProducts()
      });
      // 上拉加载
      api.addEventListener({
        name: 'scrolltobottom',
        extra: {
          threshold: -10
        }
      }, function (ret, err) {
        if (vm.hasNext) {
          vm.queryParam.pageNum++
          vm.getListProducts();
        }
      });
      api.addEventListener({
        name: 'notice-all-baby'
      }, function (ret, err) {
        var item = ret.value.item
        if(item.name == '综合'){
          vm.queryParam.orderBy = null
        }else if (item.name == '销量'){
          vm.queryParam.orderBy = item.secondSelected ? 'SALES_ASC':'SALES_DESC'
        }else if (item.name == '新品'){
          vm.queryParam.orderBy = item.secondSelected ? 'UPDATE_TIME_ASC':'UPDATE_TIME_DESC'
        }else if (item.name == '价格'){
          vm.queryParam.orderBy = item.secondSelected ? 'PRICE_ASC':'PRICE_DESC'
        }
        vm.queryParam.pageNum = 1
        vm.listProduct = []
        vm.getListProducts();
      });
    }
  </script>
</body>

</html>
